import 'package:bitcoin_mine/controllers/subscription_controller.dart';
import 'package:bitcoin_mine/services/in_app_purchase_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../config/app_config.dart';
import '../l10n/app_localizations.dart';
import '../routes/app_routes.dart';

class RestorePurchasesSection extends StatelessWidget {
  const RestorePurchasesSection({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 10.w, vertical: 20.h),
      child: Column(
        children: [
          // 标题
          GestureDetector(
            onTap: () {
              // Get.toNamed(AppRoutes.restorePurchases);
              Get.find<InAppPurchaseService>().restorePurchases();
            },
            child: Text(
              'RESTORE PURCHASES',
              style: TextStyle(color: Colors.white, fontSize: 18.sp),
            ),
          ),

          SizedBox(height: 8.h),

          // 副标题
          Text(
            'Renewal Instructions',
            style: TextStyle(
              color: Colors.white,
              fontSize: 16.sp,
              fontWeight: FontWeight.bold,
            ),
            textAlign: TextAlign.center,
          ),
          SizedBox(height: 8.h),
          // 说明文本
          SizedBox(
            width: double.infinity,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(
                  textAlign: TextAlign.center,
                  'Payment charged to your App Store account on purchase.Autorenews unless canceled at least 24 hours before end of period.Manage subscriptions on App Store settings.',
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 12.sp,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ],
            ),
          ),

          SizedBox(height: 16.h),

          // 法律链接
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Builder(
                builder: (context) {
                  final localizations = AppLocalizations.of(context);
                  return GestureDetector(
                    onTap: () {
                      Get.toNamed(
                        AppRoutes.webView,
                        arguments: {
                          'url': AppConfig.userAgreementUrl,
                          'title': localizations.userAgreement,
                        },
                      );
                    },
                    child: Text(
                      '《${localizations.userAgreement}》',
                      style: TextStyle(
                        color: const Color(0xFF05FFFD),
                        fontSize: 12.sp,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  );
                },
              ),

              SizedBox(width: 16.w),

              Builder(
                builder: (context) {
                  final localizations = AppLocalizations.of(context);
                  return GestureDetector(
                    onTap: () {
                      Get.toNamed(
                        AppRoutes.webView,
                        arguments: {
                          'url': AppConfig.privacyPolicyUrl,
                          'title': localizations.privacyPolicy,
                        },
                      );
                    },
                    child: Text(
                      '《${localizations.privacyPolicy}》',
                      style: TextStyle(
                        color: const Color(0xFF05FFFD),
                        fontSize: 12.sp,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  );
                },
              ),
            ],
          ),
        ],
      ),
    );
  }
}
